package org.supper.auth.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.supper.auth.utils.JsonResult;


@ControllerAdvice
public class AuthException {
    /**
     * 用来处理该类型的异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(FeignBadRequestException.class)
    public JsonResult handlerException(FeignBadRequestException e){
        JsonResult jsonResult = new JsonResult();
        // 密码错误
        if (e.getMessage().contains("Bad credentials")){
            jsonResult.setMsg("密码错误");
            jsonResult.setCode("500");
        } else if(e.getMessage().contains("unauthorized")){
            jsonResult.setMsg("用户名错误");
            jsonResult.setCode("500");
        } else if (e.getMessage().contains("Incorrect sms code,please check")){
            jsonResult.setMsg("验证码错误");
            jsonResult.setCode("500");
        } else if (e.getMessage().contains("Invalid mobile!")){
            jsonResult.setMsg("无效的手机号");
            jsonResult.setCode("500");
        } else {
            jsonResult.setMsg(e.getMessage());
            jsonResult.setCode("500");
        }
        return jsonResult;
    }
}
